package com.atguigu.spzx.product.controller;

import com.atguigu.spzx.model.entity.product.Category;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.common.ResultCodeEnum;
import com.atguigu.spzx.product.service.CategoryService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Tag(name = "分类管理")
@RestController
@RequestMapping("/api/product/category")
//@CrossOrigin //临时，解决跨域问题
public class CategoryController {

    @Autowired
    CategoryService categoryService;

    @Operation(summary = "三级分类加载")
    @GetMapping("/findCategoryTree")
    public Result<List<Category>> findCategoryTree(){
        //组装好父子关系
        List<Category> oneCategoryList = categoryService.findCategoryTree();
        return Result.build(oneCategoryList, ResultCodeEnum.SUCCESS);
    }
}
